package com.ruoyi.common.mytools;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.*;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;

public class AliyunSMS {

    public static void SendMessage(String PhoneNumber,String code){
        DefaultProfile profile = DefaultProfile.getProfile("cn-shenzhen", "LTAI5tAuWkc3zx8x2zrXgdVT", "E5DugzbKgDPhxUakwtWh7mLNByD0dB");
        IAcsClient client = new DefaultAcsClient(profile);

        // 创建API请求并设置参数
        SendSmsRequest request = new SendSmsRequest();

        request.setPhoneNumbers(PhoneNumber); // 该参数值为假设值，请您根据实际情况进行填写
        request.setTemplateCode("SMS_493220219"); //SMS_465580116
        request.setSignName("昱励画室"); // 该参数值为假设值，请您根据实际情况进行填写 //广州市昱励文化传播
        request.setTemplateParam("{code:"+code+"}");

        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println(JSON.toJSONString(response));
            // 打印您需要的返回值，此处打印的是此次请求的 RequestId
            System.out.println(response.getRequestId());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            // 打印错误码
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    }


    //发送预约通知
    //你有一条上课${name}预约，时间是${time}请及时前往后台查看！subscribes
    public static void SendSubscribesMessage(String PhoneNumber,String sname,String stime){
        DefaultProfile profile = DefaultProfile.getProfile("cn-shenzhen", "LTAI5tAuWkc3zx8x2zrXgdVT", "E5DugzbKgDPhxUakwtWh7mLNByD0dB");
        IAcsClient client = new DefaultAcsClient(profile);

        // 创建API请求并设置参数
        SendSmsRequest request = new SendSmsRequest();

        request.setPhoneNumbers(PhoneNumber); // 该参数值为假设值，请您根据实际情况进行填写
        request.setTemplateCode("SMS_465625410");
        request.setSignName("广州市昱励文化传播"); // 该参数值为假设值，请您根据实际情况进行填写
        //code在这里没用，只需要填写code和time参数即可
        request.setTemplateParam("{\"code\":\"0\",\"name\":\""+sname+"\",\"time\":\""+stime+"\"}");

        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println(JSON.toJSONString(response));
            // 打印您需要的返回值，此处打印的是此次请求的 RequestId
            System.out.println(response.getRequestId());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            // 打印错误码
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    }



    //发送预约通知
    //尊敬的${name}用户，您的初始登录密码为${password}，请妥善保管请勿泄露，如需修改请登录后前往个人中心设置。
    public static void SendInialLoginAndPassWord(String PhoneNumber,String username,String password){
        DefaultProfile profile = DefaultProfile.getProfile("cn-shenzhen", "LTAI5tAuWkc3zx8x2zrXgdVT", "E5DugzbKgDPhxUakwtWh7mLNByD0dB");
        IAcsClient client = new DefaultAcsClient(profile);

        // 创建API请求并设置参数
        SendSmsRequest request = new SendSmsRequest();

        request.setPhoneNumbers(PhoneNumber); // 该参数值为假设值，请您根据实际情况进行填写
        request.setTemplateCode("SMS_468445189");
        request.setSignName("广州市昱励文化传播"); // 该参数值为假设值，请您根据实际情况进行填写
        //code在这里没用，只需要填写code和time参数即可
        request.setTemplateParam("{\"code\":\"0\",\"name\":\""+username+"\",\"password\":\""+password+"\"}");

        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println(JSON.toJSONString(response));
            // 打印您需要的返回值，此处打印的是此次请求的 RequestId
            System.out.println(response.getRequestId());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            // 打印错误码
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    }

}
